<%@ taglib
	uri="http://java.sun.com/jsp/jstl/core"
	prefix="c"%>


<form
  name="userLogin"
  action="j_spring_security_check"
  method="POST"
  id="userLogin">
  <div
    id="content"
    class="signin">


    <div class="sideContent">
      <h2>Welcome</h2>
      <p>Education has been at the core of the AAAs mission since its inception. As
        the world's leading source of alternative dispute resolution education, AAAU
        provides neutrals, advocates, counsel and other professionals with a wide spectrum
        of education and training events and resources.</p>

      <!-- <h2>Welcome</h2>
                    <p>Education  has been at the core of the AAA's mission since its inception. As the  world's leading source of alternative dispute resolution education, AAAU  provides neutrals, advocates, counsel and other professionals with a  wide spectrum of education and training events and resources.</p>
                  -->
      <div class="bottomContent">


        <h3>Login</h3>
        <span class="errorMsg">
        	<c:if test="${param.loginfail == 'true'}">
    			Login failed. Invalid username/password combination.
			</c:if>
        </span>
        <div class="logInfo">
          <div class="item">
            <label>Username</label> <input
              name="j_username"
              type="text"
              id="ContentPlaceHolderDefault_bodyContent_homeLogin_UserName" /> <span
              id="ContentPlaceHolderDefault_bodyContent_homeLogin_UserNameRequired"
              class="asterisk"
              style="visibility: hidden;">*</span>
          </div>
          <div class="item">
            <label>Password</label> <input
              name="j_password"
              type="password"
              id="ContentPlaceHolderDefault_bodyContent_homeLogin_Password" /> <span
              id="ContentPlaceHolderDefault_bodyContent_homeLogin_PasswordRequired"
              class="asterisk"
              style="visibility: hidden;">*</span>
          </div>
          <div class="item">
            <input
              type="submit"
              value=""
              name="ctl00$ctl00$ctl00$ContentPlaceHolderDefault$bodyContent$homeLogin$Login"
              id="ContentPlaceHolderDefault_bodyContent_homeLogin_Login" />
          </div>
        </div>
        <div class="other">
          <input
            id="ContentPlaceHolderDefault_bodyContent_homeLogin_RememberMe"
            type="checkbox"
            name="ctl00$ctl00$ctl00$ContentPlaceHolderDefault$bodyContent$homeLogin$RememberMe" />
          <label for="ContentPlaceHolderDefault_bodyContent_homeLogin_RememberMe">
            Remember my login </label> <a
            href="#"
            id="forgotPasswd"
            class="red"> Forgot Password? </a>
        </div>
        <div
          id="forgotPasswdBox"
          style="display: none">

          <p>Forgot your Password?</p>
          <div
            class="box"
            id="emailQuestBox">
            <div
              class="item"
              id="emailBox">
              <label for="frgtEmail">Email</label> <input
                type="email"
                name="frgtEmail"
                id="frgtEmail" /> <a
                href="#"
                id="sbtGetQuest"
                class="red">submit</a>&nbsp;|&nbsp;<a
                href="#"
                class="close red">cancel</a>
            </div>
            <div
              class="item"
              id="questBox">
              <label
                id="passwdQuestion"
                for="answerQuestion"></label> <input
                type="text"
                id="answerQuestion" /> <a
                href="#"
                id="sbtAnswerQuest"
                class="red">submit</a>&nbsp;|&nbsp;<a
                href="#"
                class="close red">cancel</a>
            </div>

          </div>
          <div
            class="box"
            id="passwordBox">
            <div class="item">
              <label
                id="lblNewPass"
                for="newPass"
                class="newPass">Enter a new Password</label> <input
                type="password"
                id="newPass"
                class="newPass" />
            </div>
            <div class="item">
              <label
                id="lblConfPass"
                for="confPass"
                class="newPass">Confirm your Password</label> <input
                type="password"
                id="confPass"
                class="newPass" />
            </div>
            <a
              href="#"
              id="sbtUpdatePass"
              class="red">submit</a>

          </div>

        </div>


        <div id="loginRegisterContainer">
          <a
            class="signup"
            href="create-account"></a> <span class="red">Track registered events
            and maintain a transcript</span>
        </div>
        <a
          href="home"
          class="browse-event">Not ready to sign up; browse AAAU for events that
          interest you.<span>&nbsp;&nbsp;</span> </a>

      </div>
    </div>

    <img
      id="loginSideImage"
      src="resources/img/img_signinpage1.jpg"
      width="382"
      height="318" />
  </div>

  <script type="text/javascript">
	var counter = 0;
	var imgs = ["resources/img/img_signinpage1.jpg",
                 "resources/img/img_signinpage2.jpg", "resources/img/img_signinpage3.jpg"];

	$(function () {
	  rotateImage();

	  $('#forgotPasswd').live('click', function () {
	    //alert("HERE");
	    $('#forgotPasswdBox').show();
	    $('#emailQuestBox').show();
	    $('#emailBox').show();
	    $('input').val("");
	    return false;
	  });
	  $('.close').live('click', function () {
	    // alert("HERE");
	    $('#frgtEmail').val();
	    $('#passwordBox').hide();
	    $('#emailQuestBox').hide();
	    $('#questBox').hide();
	    $('#forgotPasswdBox').hide();
	    $('input').val('');
	    $('#forgotPasswdBox label').show();
	    return false;
	  });

	  $('#sbtGetQuest').live('click',

	  function () {
	    var obj = $(this);
	    var strEmail = $('#frgtEmail').val();
	    var sendEmail = $.ajax({
	      type: "GET",
	      async: false,
	      dataType: 'text',
	      url: "base/documentAjaxUpdate/getPasswordQuestion/?email=" + strEmail,
	      beforeSend: function () {

	        $('#sbtGetQuest').html('').addClass('spinner');
	      },
	      complete: function () {

	        $('#sbtGetQuest').removeClass().html('<span>submit</span>').addClass('red');
	      }
	    }).responseText;

	    $('#passwdQuestion').html(sendEmail).show();
	    if (sendEmail == "user not found") {
	      alert("We could not find an account that matches the email address you entered")
	      return false;
	    } else {
	      $('#emailBox').hide();
	      $('#questBox').show();
	      $('#sbtAnswerQuest').live('click',

	      function () {
	        var answer = $('#answerQuestion').val();

	        var confQuestion = $.ajax({
	          type: "GET",
	          async: false,
	          dataType: 'text',
	          url: "base/documentAjaxUpdate/verifyPasswordQuestion/?email=" + strEmail + "&answer=" + answer,
	          beforeSend: function () {
	            $('#sbtAnswerQuest').html('').addClass('spinner');
	          },
	          complete: function () {
	            $('#sbtAnswerQuest').removeClass().html('<span>submit</span>');
	          }
	        }).responseText;

	        if (confQuestion == "Failed") {
	          alert("Your answer to the security Question failed");
	        } else {
	          alert("Please select a new password");

	          $('#questBox').hide();
	          $('#emailQuestBox').hide();
	          $('#passwordBox').show();
	        }
	        return false;
	      });
	    }
	    return false;
	  });
	  $('#sbtUpdatePass').live('click',

	  function () {
	    var obj = $(this);
	    var strEmail = $('#frgtEmail').val();
	    var answer = $('#answerQuestion').val();
	    //alert(strEmail+" "+answer);
	    if ($('#newPass').val() != '' && $('#confPass').val() != '') {
	      if ($('#newPass').val() != $('#confPass').val()) {
	        alert("Passwords do not match");
	        return false;
	      }
	    } else {
	      alert("Please enter a password");
	      return false;
	    }
	    var changePW = $.ajax({
	      type: "POST",
	      async: false,
	      dataType: 'text',
	      data: {
	        email: strEmail,
	        answer: answer,
	        pass: $('#newPass').val()
	      },
	      url: "base/documentAjaxUpdate/changePassword/",
	      beforeSend: function () {
	        $('#sbtUpdatePass').addClass('spinner').text('');
	      },
	      complete: function () {

	        $('#sbtUpdatePass').removeClass().html('<span>submit</span>');
	      },
	      failure: function () {
	        alert("There was an error changing your password.  Please try again later");
	      }
	    }).responseText;
	    if (changePW == "Failed") {
	      alert("There was an error changing your password.  Please try again later");
	    } else {
	      window.location = "my-aaau";
	    }
	    return false;
	  });

	  $('.logInfo input[type=text],.logInfo input[type=password],#forgotPasswdBox input').live({
	    focus: function () {
	      if ($(this).val() == "") {
	        $(this).siblings('label').hide();
	      }
	    },
	    blur: function () {
	      if ($(this).val() == "") {
	        $(this).siblings('label').fadeIn();
	      }
	    }
	  });
	  $('.logInfo input[type=text],.logInfo input[type=password],#forgotPasswdBox input[type=email]').each(function () {
	    if ($(this).val() != "") {
	      $(this).siblings('label').hide();
	    }
	  });

	});

	function rotateImage() {
	  if (counter > 2) {
	    counter = 0;
	  }
	  $('#loginSideImage').attr('src', imgs[counter]);
	  counter++;
	  setTimeout("rotateImage();", 7000);
	};  
  </script>

</form>